home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Mops 2.7 / Mops source / Nuc source / Setup.asm < prev   
Assembly Source File  |  1995-11-24  |  4KB  |  155 lines

  1. ; This file contains the code which initializes the system.
  2.  
  3.     jtbl    run
  4.     ref    main
  5.  
  6.     ipath    "::mops source:nuc source:"
  7.  
  8.     IF1
  9.     incl    "macrox.asm"
  10.     incl    "globals.psm"
  11.     ENDI
  12.  
  13. ;            ========================
  14.  
  15. sbase    equ    *+32766
  16.  
  17.     bra.s    run
  18.  
  19. maxDic    dc.l    700000    ; These correspond to the quantities in the
  20. minHeap    dc.l    20000    ;  main dictionary with the same names.
  21. dicSize    dc.l    0    ; We compute DicSize here, and the others
  22. StkSpace    dc.l    50000    ;  are set up by Install.  Just to be safe,
  23. RstkSpace    dc.l    6000    ; When Main starts, it copies them from here
  24.             ; to the main dic.  These values are the
  25.             ; defaults, and will be the initial values
  26.             ; displayed in the Install dialog the first
  27.             ; time it's run using a freshly assembled
  28.             ; nucleus.
  29. installed    dc.b    0    ; Set NZ by Install if this is an installed
  30.             ;  application
  31. spare    dc.b    0
  32.  
  33. run    nop        ; Space for a debugger trap if necessary
  34.  
  35. ; NOTE: all the above quantities are at offsets from the start which are ASSUMED by
  36. ; Install.  Don't move anything without checking Install!!
  37.  
  38.     move.l    CurrentA5,a5    ; In case we're restarting after a crash
  39.     lea    sbase,a3    ; Make us addressable
  40.  
  41.     move.l    #$CDCD,-(a7)    ; Safety margin on return stack, with markers.
  42.     move.l    #$ABAB,-(a7)    ; These are easy to recognize in Macsbug,
  43.             ;  and the top one is odd in case we
  44.             ;  try to use it as a return address.
  45.     move.l    a7,d7    ; Leave R0 value in D7 for Main
  46.     move.l    a7,a0
  47.     sub.l    RstkSpace,a0
  48.     clr.l    -(a0)
  49.     clr.l    -(a0)
  50.     move.l    #$CD,-(a0)    ; Set up data stack:
  51.     move.l    #$AB,-(a0)    ; Safety margin on data stack, with markers
  52.     move.l    a0,a6
  53.     move.l    a0,d6    ; Leave S0 value in D6 for Main
  54.  
  55.     sub.l    StkSpace,A0    ; Reserve data stack space
  56.     move.l    a0,d4    ; Save addr for after _InitGraf etc.
  57.     exg    a6,a7    ; Setup for system calls
  58.     pea    -4(a5)
  59.     _InitGraf
  60.     move.l    d4,a0
  61.     _SetApplLimit
  62.     _MaxApplZone
  63.     _MaxMem        ; Leaves D0 = max available heap block size
  64.     move.l    d0,d3    ; Save in D3 for later
  65.     _InitFonts  
  66. ;    MOVE.L    #$0000FFFF,D0
  67. ;    _FlushEvents    ; (whichMask,stopMask:EventMask)
  68.             ; Hmmm.  Do we really need to flush
  69.             ;  events?  Typeahead could be
  70.             ;  useful.
  71.     _InitWindows  
  72.     _TeInit  
  73.     _InitMenus
  74.     _InitCursor
  75.  
  76. ; Now we check the availability of some traps:
  77.  
  78.     MOVE.W    #$9F,D0
  79.     _GetTrapAddressTool
  80.     move.l    a0,a4    ; A4 = unimplemented trap addr    
  81.     MOVEQ    #$60,D0    ; Get WaitNextEvent trap addr
  82.     _GetTrapAddressTool
  83.     cmp.l    a0,a4    ; If different from unimpl, WNE is available.
  84.     sne    d5
  85.     beq.s    .su1
  86.     moveq    #-1,d0    ; And if WNE is available, so is StripAddress
  87.     _StripAddress    ; Get StripAddress mask to D0
  88.     bra.s    .su2
  89. .su1    move.l    Lo3Bytes,d0    ; If no WNE, SA mask is Lo3Bytes
  90. .su2    move.l    d0,d4    ; Leave in D4 for Main
  91.  
  92.     lsl.l    #8,d5    ; Now we set various flags in D5 for Main
  93.     move.l    #$198,d0    ; HWpriv trap number
  94.     _GetTrapAddressOS
  95.     cmp.l    a0,a4    ; NE-> HWpriv is available
  96.     sne    d5
  97.     lsl.l    #8,d5
  98.     move.l    #$1AD,d0    ; Gestalt trap number
  99.     _GetTrapAddressOS
  100.     cmp.l    a0,a4    ; NE-> Gestalt is available
  101.     sne    d5
  102.     beq.s    .noGest
  103.     move.l    #'proc',d0    ; If so, we'll use it to get info
  104.     dc.w    $A1AD    ; _Gestalt
  105.     bne.s    .noGest
  106.     move.l    a0,-(a7)    ; Proc# to stack for Main
  107.     move.l    #'fpu ',d0
  108.     dc.w    $A1AD    ; _Gestalt
  109.     bne.s    .noFPU    ; If call failed, assume no FPU
  110.     move.l    a0,-(a7)    ; FPU status to stack for Main
  111.     beq.s    .su3
  112.     clr.l    -(a7)    ; If FPU present, initialize it as per
  113.     clr.l    -(a7)    ;  Tech Note 146.
  114.     dc.w    $F21F,$9800    ;    fmovem    (a7)+,FPCR/FPSR
  115.     bra.s    .su3
  116.  
  117. .noGest    moveq    #1,d0    ; No Gestalt, or call failed.
  118.     move.l    d0,-(a7)    ;  Assume processor is 68000.
  119. .noFPU    clr.l    -(a7)    ;  And no FPU
  120.  
  121. .su3    tst.b    installed-sbase(a3)
  122.     bne    callMain    ; If this is an installed application, skip
  123.             ;  the next bit
  124.  
  125. ; Now we set the size of the main (CODE 2) resource
  126.  
  127.     sub.l    MinHeap,d3    ; Subtract minimum heap requirement
  128.     move.l    MaxDic,d0    ; Is remaining heap bigger than max
  129.     cmp.l    d0,d3    ;  dic size needed?
  130.     blt.s    .1    ; No  - grab it all
  131.     move.l    d0,d3    ; Yes - only grab max size needed
  132. .1    move.l    d3,dicSize-sbase(a3)    ; Final dic size
  133.     clr.l    -(sp)
  134.     move.l    #'CODE',-(a7)
  135.     move.w    #2,-(a7)
  136.     _GetResource
  137.     move.l    (a7),a0    ; A0 = handle to CODE 2 (Main)
  138.     _Hunlock        ; Unlock it just in case, since we're
  139.     move.l    (a7),a0    ;  going to expand it
  140.     move.l    d3,d0
  141. ;    add.l    #nucTop-start,d0 ; Add nucleus size to dic requirement
  142.     _SetHandleSize    ; Set CODE 2 to total size
  143.     tst.l    d0    ; Did we get the memory?
  144.     beq.s    .2    ; Yes
  145.     move.w    #3,-(a7)
  146.     _SysBeep
  147.     _ExitToShell    ; No - something's terribly wrong - virus?
  148.  
  149. .2    move.l    (a7)+,a0    ; Lock CODE 2 to make sure it doesn't get
  150.     _Hlock        ;  purged since we've expanded it
  151. callMain
  152.     lea    maxDic,a2
  153.  
  154.     jmp    main
  155.